<?php

if (!defined('BASEPATH'))
    exit('No direct script access allowed');

/**
 * Cache for invidual block
 *
 * Lets you create cache html for block only.
 */
class Blockcache extends CI_Controller
{
    /*
     * type of cache data: file, memcached or apc
     */

    var $driver = 'apc';

    /*
     * expire time, default: never till delete or system restart
     */
    var $ttl = 3000;

    /*
     * extend CI 
     */
    var $_CI;
    var $lastData = '';
    var $cDriver = '';

    function Blockcache()
    {
        $this->_CI = & get_instance();
        if ($this->driver) {
            $this->_CI->load->driver('cache', array(
                'adapter'   =>  $this->driver,
                'backup'    =>  'file'
            ));
        }
    }

    /*
     * Flexible data APC cache
     * 
     * @ @author canhnm
     */

    function save($blockName, $data = null, $ttl = 3000)
    {
        $blockName = md5($blockName);
        $this->_CI->cache->file->save($blockName, $data, $ttl);
    }

    function get($blockName)
    {
        $blockName = md5($blockName);
        return $this->_CI->cache->file->get($blockName);
    }
}

?>
